<%@ page import="com.bobamrz.domain.DocType, com.bobamrz.domain.DocCatalog, com.bobamrz.domain.Document, java.util.Set, java.util.List;" %>
<script>
var documentData = <%out.print(request.getAttribute("documentData"));%>;
var availableStatuses = <%out.print(request.getAttribute("availableStatuses"));%>;
</script>
<script src="js/docView.js"></script>
<link rel="stylesheet" type="text/css" href="css/docView.css">
<div id="document_list">
<%
List<Document> docList = (List<Document>)request.getAttribute("docList");
//out.println("<script>alert('amount of documents in this catalogue: "+docList.size()+"')</script>");
boolean isCatalogEmpty = true;
for(Document doc : docList) {
	/*doc.getDocument()   --->  eto id???*/
	out.println("<a class='link_to_document' docId='" + doc.getDocument() + "' href='#'>" + doc.getName() + "</a>");
	out.println("<button id='"+doc.getDocument()+"' class='clipboardButton'>To clipboard</button><br/>");
	isCatalogEmpty=false;
}
if(isCatalogEmpty) {
	out.println("This catalogue has no documents.<br/>");
}
%>
<button id="paste">Paste from clipboard</button>
</div>
<div id="document_list">
	<p>Add new document to current catalog:</p>
	<select id="docType" class="save">
	<% List<DocType> list = (List<DocType>)request.getAttribute("availablSuperDocTypes");
	for(DocType superDocType : list) {
		out.println("<optgroup label='"+superDocType.getTypeName()+"'>");
		Set<DocType> subDocTypes = superDocType.getDocTypes();
		if(!subDocTypes.isEmpty()) {
			for(DocType subDocType : subDocTypes) {
				out.println("<option value=\"" + subDocType.getTypeName() + "\">"+subDocType.getTypeName()+"</option>");
			}
		}
		out.println("</optgroup>");
	}%>
	</select>
	<button id="add_new_doc_button">+ add new document</button>
</div>
<div id="form_wrapper" class="hidden">
	<h2>Document data:</h2>
	<form id="form">
		<div id="common">
			<label>id:</label><br/>
			<input class="save readonly" id="id" type="text" name="id">
			<br/><br/>
		
			type:<br/>
			<span id="type" class="bold">Some document type</span>
			<br/><br/>
			
			status:<br/>
			<select id="status" class="save" name="status">
			</select>
			<br/><br/>
			
			name:<br/>
			<input class="save" id="name" type="text" name="name">
			<span warning="name" class="warning"></span>
			<br/><br/>
			
			description:<br/>
			<input class="save" id="description" type="text" name="description">
			<span warning="description" class="warning"></span>
			<br/><br/>
			
			created :<br/>
			<span id="created" class="bold">11/11/1111</span>
			<br/><br/>
			
			created by:<br/>
			<span id="created_by" class="bold">Ivan Ivanov</span>
			<br/><br/>
			
			updated :<br/>
			<span id="updated" class="bold">11/11/1111</span><br/><br/>
			
			updated by:<br/>
			<span id="updated_by" class="bold">Bazil Pupkin</span><br/><br/>
		</div>
		<div id="attributes">
			
		</div>
		<button id="saveNewDocButton">Save new document</button>
		<button id="updateThisDocButton">Update document data</button>
		<span class="success">Succeed!</span>
		<span class="not_saved_warning">Data was not saved. Please correct errors.</span>
		
	</form> 
</div>